using System;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace MaterialUI
{
	[ExecuteInEditMode]
	[RequireComponent(typeof(InputField))]
	[RequireComponent(typeof(CanvasGroup))]
	[AddComponentMenu("MaterialUI/Material Input Field", 100)]
	public class MaterialInputField : UIBehaviour, ILayoutGroup, ILayoutElement, ISelectHandler, IDeselectHandler, ILayoutController, IEventSystemHandler
	{
		public enum ColorSelectionState
		{
			EnabledSelected,
			EnabledDeselected,
			DisabledSelected,
			DisabledDeselected
		}

		[SerializeField]
		private string m_HintText;

		[SerializeField]
		private bool m_FloatingHint = true;

		[SerializeField]
		private bool m_HasValidation = true;

		[SerializeField]
		private bool m_ValidateOnStart;

		[SerializeField]
		private bool m_HasCharacterCounter = true;

		[SerializeField]
		private bool m_MatchInputFieldCharacterLimit = true;

		[SerializeField]
		private int m_CharacterLimit;

		[SerializeField]
		private int m_FloatingHintFontSize = 12;

		[SerializeField]
		private bool m_FitHeightToContent = true;

		[SerializeField]
		private Vector2 m_LeftContentOffset;

		[SerializeField]
		private Vector2 m_RightContentOffset;

		[SerializeField]
		private bool m_ManualPreferredWidth;

		[SerializeField]
		private bool m_ManualPreferredHeight;

		[SerializeField]
		private Vector2 m_ManualSize;

		[SerializeField]
		private GameObject m_TextValidator;

		[SerializeField]
		private RectTransform m_RectTransform;

		[SerializeField]
		private InputField m_InputField;

		[SerializeField]
		private RectTransform m_InputTextTransform;

		[SerializeField]
		private RectTransform m_HintTextTransform;

		[SerializeField]
		private RectTransform m_CounterTextTransform;

		[SerializeField]
		private RectTransform m_ValidationTextTransform;

		[SerializeField]
		private RectTransform m_LineTransform;

		[SerializeField]
		private RectTransform m_ActiveLineTransform;

		[SerializeField]
		private RectTransform m_LeftContentTransform;

		[SerializeField]
		private RectTransform m_RightContentTransform;

		[SerializeField]
		private Text m_InputText;

		[SerializeField]
		private Text m_HintTextObject;

		[SerializeField]
		private Text m_CounterText;

		[SerializeField]
		private Text m_ValidationText;

		[SerializeField]
		private Image m_LineImage;

		[SerializeField]
		private CanvasGroup m_ActiveLineCanvasGroup;

		[SerializeField]
		private CanvasGroup m_HintTextCanvasGroup;

		[SerializeField]
		private CanvasGroup m_ValidationCanvasGroup;

		private MaterialUIScaler m_MaterialUiScaler;

		private RectTransform m_CaretTransform;

		[SerializeField]
		private Color m_LeftContentActiveColor = MaterialColor.iconDark;

		[SerializeField]
		private Color m_LeftContentInactiveColor = MaterialColor.disabledDark;

		[SerializeField]
		private Color m_RightContentActiveColor = MaterialColor.iconDark;

		[SerializeField]
		private Color m_RightContentInactiveColor = MaterialColor.disabledDark;

		[SerializeField]
		private Color m_HintTextActiveColor = MaterialColor.textHintDark;

		[SerializeField]
		private Color m_HintTextInactiveColor = MaterialColor.disabledDark;

		[SerializeField]
		private Color m_LineActiveColor = Color.black;

		[SerializeField]
		private Color m_LineInactiveColor = MaterialColor.disabledDark;

		[SerializeField]
		private Color m_ValidationActiveColor = MaterialColor.red500;

		[SerializeField]
		private Color m_ValidationInactiveColor = MaterialColor.disabledDark;

		[SerializeField]
		private Color m_CounterActiveColor = MaterialColor.textSecondaryDark;

		[SerializeField]
		private Color m_CounterInactiveColor = MaterialColor.disabledDark;

		[SerializeField]
		private Graphic m_LeftContentGraphic;

		[SerializeField]
		private Graphic m_RightContentGraphic;

		[SerializeField]
		private float m_HintTextFloatingValue;

		[SerializeField]
		private bool m_Interactable = true;

		private CanvasGroup m_CanvasGroup;

		private static Sprite m_LineDisabledSprite;

		private ITextValidator m_CustomTextValidator;

		[SerializeField]
		private bool m_LastCounterState;

		private bool m_AnimateHintText;

		private bool m_HasBeenSelected;

		private int m_LeftContentTweener;

		private int m_RightContentTweener;

		private int m_HintTextTweener;

		private int m_ValidationColorTweener;

		private int m_CounterTweener;

		private Vector2 m_LastSize;

		private bool m_LastFocussedState;

		private ColorSelectionState m_CurrentSelectionState;

		private ColorSelectionState m_LastSelectionState;

		private float m_TopSectionHeight;

		private float m_BottomSectionHeight;

		private float m_LeftSectionWidth;

		private float m_RightSectionWidth;

		[SerializeField]
		private float m_AnimationDuration = 0.25f;

		private int m_ActiveLinePosTweener;

		private int m_ActiveLineSizeTweener;

		private int m_ActiveLineAlphaTweener;

		private int m_HintTextFloatingValueTweener;

		private int m_ValidationTweener;

		private Vector2 m_LastRectPosition;

		private Vector2 m_LastRectSize;

		private Vector2 m_LayoutSize;

		public string hintText
		{
			get
			{
				return m_HintText;
			}
			set
			{
				m_HintText = value;
				hintTextObject.text = value;
			}
		}

		public bool floatingHint
		{
			get
			{
				return m_FloatingHint;
			}
			set
			{
				m_FloatingHint = value;
				SetLayoutDirty();
			}
		}

		public bool hasValidation
		{
			get
			{
				return m_HasValidation;
			}
			set
			{
				m_HasValidation = value;
				SetLayoutDirty();
				ValidateText();
			}
		}

		public bool validateOnStart
		{
			get
			{
				return m_ValidateOnStart;
			}
			set
			{
				m_ValidateOnStart = value;
				if (value)
				{
					ValidateText();
				}
			}
		}

		public bool hasCharacterCounter
		{
			get
			{
				return m_HasCharacterCounter;
			}
			set
			{
				m_HasCharacterCounter = value;
				m_CounterText.gameObject.SetActive(m_HasCharacterCounter);
				SetLayoutDirty();
				UpdateCounter();
			}
		}

		public bool matchInputFieldCharacterLimit
		{
			get
			{
				return m_MatchInputFieldCharacterLimit;
			}
			set
			{
				m_MatchInputFieldCharacterLimit = value;
				SetLayoutDirty();
				UpdateCounter();
			}
		}

		public int characterLimit
		{
			get
			{
				return m_CharacterLimit;
			}
			set
			{
				m_CharacterLimit = value;
				SetLayoutDirty();
				UpdateCounter();
			}
		}

		public int floatingHintFontSize
		{
			get
			{
				return m_FloatingHintFontSize;
			}
			set
			{
				m_FloatingHintFontSize = value;
				SetLayoutDirty();
			}
		}

		public bool fitHeightToContent
		{
			get
			{
				return m_FitHeightToContent;
			}
			set
			{
				m_FitHeightToContent = value;
				SetLayoutDirty();
			}
		}

		public bool manualPreferredWidth
		{
			get
			{
				return m_ManualPreferredWidth;
			}
			set
			{
				m_ManualPreferredWidth = value;
				SetLayoutDirty();
			}
		}

		public bool manualPreferredHeight
		{
			get
			{
				return m_ManualPreferredHeight;
			}
			set
			{
				m_ManualPreferredHeight = value;
				SetLayoutDirty();
			}
		}

		public Vector2 manualSize
		{
			get
			{
				return m_ManualSize;
			}
			set
			{
				m_ManualSize = value;
				SetLayoutDirty();
			}
		}

		public GameObject textValidator
		{
			get
			{
				return m_TextValidator;
			}
			set
			{
				m_TextValidator = value;
				ValidateText();
			}
		}

		public RectTransform rectTransform
		{
			get
			{
				if (m_RectTransform == null)
				{
					m_RectTransform = (RectTransform)base.transform;
				}
				return m_RectTransform;
			}
		}

		public InputField inputField
		{
			get
			{
				if (m_InputField == null)
				{
					m_InputField = GetComponent<InputField>();
				}
				return m_InputField;
			}
		}

		public RectTransform inputTextTransform
		{
			get
			{
				if (m_InputTextTransform == null && m_InputField != null && m_InputField.textComponent != null)
				{
					m_InputTextTransform = m_InputField.textComponent.GetComponent<RectTransform>();
				}
				return m_InputTextTransform;
			}
		}

		public RectTransform hintTextTransform
		{
			get
			{
				return m_HintTextTransform;
			}
			set
			{
				m_HintTextTransform = value;
				SetLayoutDirty();
				UpdateCounter();
				UpdateSelectionState();
				ValidateText();
			}
		}

		public RectTransform counterTextTransform
		{
			get
			{
				return m_CounterTextTransform;
			}
			set
			{
				m_CounterTextTransform = value;
				SetLayoutDirty();
				UpdateCounter();
				UpdateSelectionState();
				ValidateText();
			}
		}

		public RectTransform validationTextTransform
		{
			get
			{
				return m_ValidationTextTransform;
			}
			set
			{
				m_ValidationTextTransform = value;
				SetLayoutDirty();
				UpdateCounter();
				UpdateSelectionState();
				ValidateText();
			}
		}

		public RectTransform lineTransform
		{
			get
			{
				return m_LineTransform;
			}
			set
			{
				m_LineTransform = value;
				SetLayoutDirty();
				UpdateSelectionState();
			}
		}

		public RectTransform activeLineTransform
		{
			get
			{
				return m_ActiveLineTransform;
			}
			set
			{
				m_ActiveLineTransform = value;
				SetLayoutDirty();
				UpdateSelectionState();
			}
		}

		public RectTransform leftContentTransform
		{
			get
			{
				return m_LeftContentTransform;
			}
			set
			{
				m_LeftContentTransform = value;
				SetLayoutDirty();
				UpdateSelectionState();
			}
		}

		public RectTransform rightContentTransform
		{
			get
			{
				return m_RightContentTransform;
			}
			set
			{
				m_RightContentTransform = value;
				SetLayoutDirty();
				UpdateSelectionState();
			}
		}

		public Text inputText
		{
			get
			{
				if (m_InputText == null && inputTextTransform != null)
				{
					m_InputText = inputTextTransform.GetComponent<Text>();
				}
				return m_InputText;
			}
		}

		public Text hintTextObject
		{
			get
			{
				if (m_HintTextObject == null && m_HintTextTransform != null)
				{
					m_HintTextObject = m_HintTextTransform.GetComponent<Text>();
				}
				return m_HintTextObject;
			}
		}

		public Text counterText
		{
			get
			{
				if (m_CounterText == null && m_CounterTextTransform != null)
				{
					m_CounterText = m_CounterTextTransform.GetComponent<Text>();
				}
				return m_CounterText;
			}
		}

		public Text validationText
		{
			get
			{
				if (m_ValidationText == null && m_ValidationTextTransform != null)
				{
					m_ValidationText = m_ValidationTextTransform.GetComponent<Text>();
				}
				return m_ValidationText;
			}
		}

		public Image lineImage
		{
			get
			{
				if (m_LineImage == null && m_LineTransform != null)
				{
					m_LineImage = m_LineTransform.GetComponent<Image>();
				}
				return m_LineImage;
			}
		}

		public CanvasGroup activeLineCanvasGroup
		{
			get
			{
				if (m_ActiveLineCanvasGroup == null && m_ActiveLineTransform != null)
				{
					m_ActiveLineCanvasGroup = m_ActiveLineTransform.GetComponent<CanvasGroup>();
				}
				return m_ActiveLineCanvasGroup;
			}
		}

		public CanvasGroup hintTextCanvasGroup
		{
			get
			{
				if (m_HintTextCanvasGroup == null && m_HintTextTransform != null)
				{
					m_HintTextCanvasGroup = m_HintTextTransform.GetComponent<CanvasGroup>();
				}
				return m_HintTextCanvasGroup;
			}
		}

		public CanvasGroup validationCanvasGroup
		{
			get
			{
				if (m_ValidationCanvasGroup == null && m_ValidationTextTransform != null)
				{
					m_ValidationCanvasGroup = m_ValidationTextTransform.GetComponent<CanvasGroup>();
				}
				return m_ValidationCanvasGroup;
			}
		}

		public MaterialUIScaler materialUiScaler
		{
			get
			{
				if (m_MaterialUiScaler == null)
				{
					m_MaterialUiScaler = MaterialUIScaler.GetParentScaler(base.transform);
				}
				return m_MaterialUiScaler;
			}
		}

		public RectTransform caretTransform
		{
			get
			{
				if (m_CaretTransform == null)
				{
					LayoutElement[] componentsInChildren = GetComponentsInChildren<LayoutElement>();
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						if (componentsInChildren[i].name == base.name + " Input Caret")
						{
							m_CaretTransform = (RectTransform)componentsInChildren[i].transform;
						}
					}
				}
				return m_CaretTransform;
			}
		}

		public Color leftContentActiveColor
		{
			get
			{
				return m_LeftContentActiveColor;
			}
			set
			{
				m_LeftContentActiveColor = value;
			}
		}

		public Color leftContentInactiveColor
		{
			get
			{
				return m_LeftContentInactiveColor;
			}
			set
			{
				m_LeftContentInactiveColor = value;
			}
		}

		public Color rightContentActiveColor
		{
			get
			{
				return m_RightContentActiveColor;
			}
			set
			{
				m_RightContentActiveColor = value;
			}
		}

		public Color rightContentInactiveColor
		{
			get
			{
				return m_RightContentInactiveColor;
			}
			set
			{
				m_RightContentInactiveColor = value;
			}
		}

		public Color hintTextActiveColor
		{
			get
			{
				return m_HintTextActiveColor;
			}
			set
			{
				m_HintTextActiveColor = value;
			}
		}

		public Color hintTextInactiveColor
		{
			get
			{
				return m_HintTextInactiveColor;
			}
			set
			{
				m_HintTextInactiveColor = value;
			}
		}

		public Color lineActiveColor
		{
			get
			{
				return m_LineActiveColor;
			}
			set
			{
				m_LineActiveColor = value;
			}
		}

		public Color lineInactiveColor
		{
			get
			{
				return m_LineInactiveColor;
			}
			set
			{
				m_LineInactiveColor = value;
			}
		}

		public Color validationActiveColor
		{
			get
			{
				return m_ValidationActiveColor;
			}
			set
			{
				m_ValidationActiveColor = value;
			}
		}

		public Color validationInactiveColor
		{
			get
			{
				return m_ValidationInactiveColor;
			}
			set
			{
				m_ValidationInactiveColor = value;
			}
		}

		public Color counterActiveColor
		{
			get
			{
				return m_CounterActiveColor;
			}
			set
			{
				m_CounterActiveColor = value;
			}
		}

		public Color counterInactiveColor
		{
			get
			{
				return m_CounterInactiveColor;
			}
			set
			{
				m_CounterInactiveColor = value;
			}
		}

		public Graphic leftContentGraphic
		{
			get
			{
				return m_LeftContentGraphic;
			}
			set
			{
				m_LeftContentGraphic = value;
			}
		}

		public Graphic rightContentGraphic
		{
			get
			{
				return m_RightContentGraphic;
			}
			set
			{
				m_RightContentGraphic = value;
			}
		}

		public float hintTextFloatingValue
		{
			get
			{
				return m_HintTextFloatingValue;
			}
			set
			{
				m_HintTextFloatingValue = value;
			}
		}

		public bool interactable
		{
			get
			{
				return m_Interactable;
			}
			set
			{
				m_Interactable = value;
				UpdateSelectionState();
				inputField.interactable = value;
			}
		}

		public CanvasGroup canvasGroup
		{
			get
			{
				if (!m_CanvasGroup)
				{
					m_CanvasGroup = base.gameObject.GetComponent<CanvasGroup>();
				}
				return m_CanvasGroup;
			}
		}

		private static Sprite lineDisabledSprite
		{
			get
			{
				if (m_LineDisabledSprite == null)
				{
					Color[] pixels = new Color[8]
					{
						Color.white,
						Color.white,
						Color.clear,
						Color.clear,
						Color.white,
						Color.white,
						Color.clear,
						Color.clear
					};
					Texture2D texture2D = new Texture2D(4, 2, TextureFormat.ARGB32, mipChain: false);
					texture2D.filterMode = FilterMode.Point;
					texture2D.SetPixels(pixels);
					texture2D.hideFlags = HideFlags.HideAndDontSave;
					Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, 4f, 2f), new Vector2(0.5f, 0.5f));
					sprite.hideFlags = HideFlags.HideAndDontSave;
					m_LineDisabledSprite = sprite;
				}
				return m_LineDisabledSprite;
			}
		}

		public ITextValidator customTextValidator
		{
			get
			{
				return m_CustomTextValidator;
			}
			set
			{
				m_CustomTextValidator = value;
				m_CustomTextValidator.Init(this);
			}
		}

		public float minWidth => -1f;

		public float preferredWidth => m_LayoutSize.x;

		public float flexibleWidth => -1f;

		public float minHeight => -1f;

		public float preferredHeight => m_LayoutSize.y;

		public float flexibleHeight => -1f;

		public int layoutPriority => 1;

		protected override void OnEnable()
		{
			UpdateSelectionState();
			OnTextChanged();
			CheckHintText();
			SetLayoutDirty();
		}

		protected override void OnDisable()
		{
			UpdateSelectionState();
			CheckHintText();
			SetLayoutDirty();
		}

		protected override void OnRectTransformDimensionsChange()
		{
			SetLayoutDirty();
		}

		protected override void OnDidApplyAnimationProperties()
		{
			UpdateSelectionState();
			OnTextChanged();
			CheckHintText();
			SetLayoutDirty();
		}

		protected override void Start()
		{
			UpdateSelectionState();
			OnTextChanged();
			CheckHintText();
			SetLayoutDirty();
		}

		private void Update()
		{
			if (Application.isPlaying)
			{
				if (inputField.isFocused)
				{
					m_LastFocussedState = true;
				}
				else if (m_LastFocussedState)
				{
					m_LastFocussedState = false;
					OnDeselect(new PointerEventData(EventSystem.current));
				}
				UpdateSelectionState();
				CheckHintText();
				if (m_AnimateHintText)
				{
					SetHintLayoutToFloatingValue();
				}
			}
		}

		public void ClearText()
		{
			inputField.text = string.Empty;
			OnTextChanged();
			SetLayoutDirty();
		}

		public void OnTextChanged()
		{
			UpdateCounter();
			ValidateText();
		}

		private void CheckHintText()
		{
			if (!(hintTextObject == null) && m_HintText != hintTextObject.text)
			{
				m_HintText = hintTextObject.text;
			}
		}

		private void ValidateText()
		{
			if (validationText == null || (!m_ValidateOnStart && !m_HasBeenSelected))
			{
				return;
			}
			m_ValidationText.color = ((!IsSelected()) ? m_ValidationInactiveColor : m_ValidationActiveColor);
			ITextValidator textValidator = null;
			if (m_TextValidator != null && m_TextValidator.GetComponent<ITextValidator>() != null)
			{
				textValidator = m_TextValidator.GetComponent<ITextValidator>();
				textValidator.Init(this);
			}
			if (m_CustomTextValidator != null)
			{
				textValidator = customTextValidator;
				m_HasValidation = true;
			}
			if (textValidator != null && m_HasValidation)
			{
				TweenManager.EndTween(m_ValidationTweener);
				if (!textValidator.IsTextValid())
				{
					if (Application.isPlaying)
					{
						validationCanvasGroup.gameObject.SetActive(value: true);
						validationCanvasGroup.interactable = true;
						validationCanvasGroup.blocksRaycasts = true;
						m_ValidationTweener = TweenManager.TweenFloat(delegate(float f)
						{
							validationCanvasGroup.alpha = f;
						}, validationCanvasGroup.alpha, 1f, m_AnimationDuration / 2f, 0f, null, scaledTime: false, Tween.TweenType.Linear);
						return;
					}
				}
				else if (Application.isPlaying)
				{
					m_ValidationTweener = TweenManager.TweenFloat(delegate(float f)
					{
						validationCanvasGroup.alpha = f;
					}, validationCanvasGroup.alpha, 0f, m_AnimationDuration / 2f, 0f, delegate
					{
						validationCanvasGroup.interactable = false;
						validationCanvasGroup.blocksRaycasts = false;
						validationCanvasGroup.gameObject.SetActive(value: false);
					}, scaledTime: false, Tween.TweenType.Linear);
					return;
				}
			}
			validationCanvasGroup.alpha = 0f;
			validationCanvasGroup.interactable = false;
			validationCanvasGroup.blocksRaycasts = false;
			validationCanvasGroup.gameObject.SetActive(value: false);
		}

		private void UpdateCounter()
		{
			if (!(counterText == null))
			{
				int num = (!m_MatchInputFieldCharacterLimit) ? m_CharacterLimit : inputField.characterLimit;
				string arg = (num <= 0) ? string.Empty : (" / " + num);
				counterText.text = inputField.text.Length + arg;
			}
		}

		private void UpdateSelectionState()
		{
			if (m_Interactable)
			{
				m_CurrentSelectionState = ((!inputField.isFocused) ? ColorSelectionState.EnabledDeselected : ColorSelectionState.EnabledSelected);
				if (lineImage != null)
				{
					lineImage.sprite = null;
				}
			}
			else
			{
				m_CurrentSelectionState = ((!inputField.isFocused) ? ColorSelectionState.DisabledDeselected : ColorSelectionState.DisabledSelected);
				if (lineImage != null)
				{
					lineImage.sprite = lineDisabledSprite;
					lineImage.type = Image.Type.Tiled;
				}
			}
			if (m_CurrentSelectionState == m_LastSelectionState)
			{
				return;
			}
			m_LastSelectionState = m_CurrentSelectionState;
			TweenManager.EndTween(m_LeftContentTweener);
			if (Application.isPlaying)
			{
				if ((bool)m_LeftContentGraphic)
				{
					m_LeftContentTweener = TweenManager.TweenColor(delegate(Color color)
					{
						m_LeftContentGraphic.color = color;
					}, m_LeftContentGraphic.color, (!IsSelected()) ? m_LeftContentInactiveColor : m_LeftContentActiveColor, m_AnimationDuration);
				}
			}
			else if ((bool)m_LeftContentGraphic)
			{
				m_LeftContentGraphic.color = ((!IsSelected()) ? m_LeftContentInactiveColor : m_LeftContentActiveColor);
			}
			TweenManager.EndTween(m_RightContentTweener);
			if (Application.isPlaying)
			{
				if ((bool)m_RightContentGraphic)
				{
					m_RightContentTweener = TweenManager.TweenColor(delegate(Color color)
					{
						m_RightContentGraphic.color = color;
					}, m_RightContentGraphic.color, (!IsSelected()) ? m_RightContentInactiveColor : m_RightContentActiveColor, m_AnimationDuration);
				}
			}
			else if ((bool)m_RightContentGraphic)
			{
				m_RightContentGraphic.color = ((!IsSelected()) ? m_RightContentInactiveColor : m_RightContentActiveColor);
			}
			TweenManager.EndTween(m_HintTextTweener);
			if (m_HintTextObject != null)
			{
				if (Application.isPlaying)
				{
					m_HintTextTweener = TweenManager.TweenColor(delegate(Color color)
					{
						m_HintTextObject.color = color;
					}, m_HintTextObject.color, (!IsSelected()) ? m_HintTextInactiveColor : m_HintTextActiveColor, m_AnimationDuration);
				}
				else
				{
					m_HintTextObject.color = ((!IsSelected()) ? m_HintTextInactiveColor : m_HintTextActiveColor);
				}
			}
			TweenManager.EndTween(m_CounterTweener);
			if (m_CounterText != null)
			{
				if (Application.isPlaying)
				{
					m_CounterTweener = TweenManager.TweenColor(delegate(Color color)
					{
						m_CounterText.color = color;
					}, m_CounterText.color, (!IsSelected()) ? m_CounterInactiveColor : m_CounterActiveColor, m_AnimationDuration);
				}
				else
				{
					m_CounterText.color = ((!IsSelected()) ? m_CounterInactiveColor : m_CounterActiveColor);
				}
			}
			TweenManager.EndTween(m_ValidationColorTweener);
			if (m_ValidationText != null)
			{
				if (Application.isPlaying)
				{
					m_ValidationColorTweener = TweenManager.TweenColor(delegate(Color color)
					{
						m_ValidationText.color = color;
					}, m_ValidationText.color, (!IsSelected()) ? m_ValidationInactiveColor : m_ValidationActiveColor, m_AnimationDuration);
				}
				else
				{
					m_ValidationText.color = ((!IsSelected()) ? m_ValidationInactiveColor : m_ValidationActiveColor);
				}
			}
			m_LineTransform.GetComponent<Graphic>().color = m_LineInactiveColor;
			m_ActiveLineTransform.GetComponent<Graphic>().color = m_LineActiveColor;
			canvasGroup.alpha = ((!m_Interactable) ? 0.5f : 1f);
			canvasGroup.interactable = m_Interactable;
			canvasGroup.blocksRaycasts = m_Interactable;
		}

		public bool IsSelected()
		{
			return m_CurrentSelectionState == ColorSelectionState.DisabledSelected || m_CurrentSelectionState == ColorSelectionState.EnabledSelected;
		}

		private float GetTextHeight()
		{
			string text = inputField.text;
			Vector2 extents = default(Vector2);
			if (inputField.lineType != 0)
			{
				extents = new Vector2(inputText.rectTransform.rect.width, float.MaxValue);
			}
			else
			{
				extents = new Vector2(float.MaxValue, float.MaxValue);
				text = text.Replace("\n", string.Empty);
			}
			TextGenerator cachedTextGeneratorForLayout = inputText.cachedTextGeneratorForLayout;
			TextGenerationSettings generationSettings = inputText.GetGenerationSettings(extents);
			if (materialUiScaler == null)
			{
				UnityEngine.Debug.LogError("Must have a MaterialUIScaler atached to root canvas");
				return 0f;
			}
			return cachedTextGeneratorForLayout.GetPreferredHeight(text, generationSettings) / materialUiScaler.scaler.scaleFactor;
		}

		private float GetSmallHintTextHeight()
		{
			if (hintTextObject == null)
			{
				return 0f;
			}
			if (materialUiScaler == null)
			{
				return 0f;
			}
			TextGenerator cachedTextGeneratorForLayout = hintTextObject.cachedTextGeneratorForLayout;
			TextGenerationSettings generationSettings = inputText.GetGenerationSettings(new Vector2(float.MaxValue, float.MaxValue));
			generationSettings.fontSize = m_FloatingHintFontSize;
			return cachedTextGeneratorForLayout.GetPreferredHeight(hintTextObject.text, generationSettings) / materialUiScaler.scaler.scaleFactor;
		}

		public void OnSelect(BaseEventData eventData)
		{
			m_HasBeenSelected = true;
			AnimateActiveLineSelect();
			AnimateHintTextSelect();
			UpdateSelectionState();
			ValidateText();
		}

		public void OnDeselect(BaseEventData eventData)
		{
			AnimateActiveLineDeselect();
			AnimateHintTextDeselect();
			UpdateSelectionState();
		}

		private void AnimateHintTextSelect()
		{
			CancelHintTextTweeners();
			m_HintTextFloatingValueTweener = TweenManager.TweenFloat(delegate(float f)
			{
				hintTextFloatingValue = f;
			}, hintTextFloatingValue, 1f, m_AnimationDuration, 0f, delegate
			{
				m_AnimateHintText = false;
				SetHintLayoutToFloatingValue();
			});
			m_AnimateHintText = true;
		}

		private void AnimateHintTextDeselect()
		{
			CancelHintTextTweeners();
			if (!inputField.isFocused && inputField.text.Length == 0)
			{
				m_HintTextFloatingValueTweener = TweenManager.TweenFloat((Action<float>)delegate(float f)
				{
					hintTextFloatingValue = f;
				}, (Func<float>)this.get_hintTextFloatingValue, 0f, m_AnimationDuration, 0f, (Action)delegate
				{
					m_AnimateHintText = false;
					SetHintLayoutToFloatingValue();
				}, scaledTime: false, Tween.TweenType.EaseOutQuint);
				m_AnimateHintText = true;
			}
		}

		private void AnimateActiveLineSelect(bool instant = false)
		{
			CancelActivelineTweeners();
			if (!(m_LineTransform == null) && !(m_ActiveLineTransform == null))
			{
				if (instant)
				{
					m_ActiveLineTransform.anchoredPosition = Vector2.zero;
					RectTransform activeLineTransform = m_ActiveLineTransform;
					Vector2 properSize = m_LineTransform.GetProperSize();
					float x = properSize.x;
					Vector2 sizeDelta = m_ActiveLineTransform.sizeDelta;
					activeLineTransform.sizeDelta = new Vector2(x, sizeDelta.y);
					activeLineCanvasGroup.alpha = 1f;
					return;
				}
				Vector2 properSize2 = m_LineTransform.GetProperSize();
				float x2 = properSize2.x;
				RectTransform activeLineTransform2 = m_ActiveLineTransform;
				Vector2 sizeDelta2 = m_ActiveLineTransform.sizeDelta;
				activeLineTransform2.sizeDelta = new Vector2(0f, sizeDelta2.y);
				m_ActiveLineTransform.position = UnityEngine.Input.mousePosition;
				RectTransform activeLineTransform3 = m_ActiveLineTransform;
				Vector2 anchoredPosition = m_ActiveLineTransform.anchoredPosition;
				activeLineTransform3.anchoredPosition = new Vector2(Mathf.Clamp(anchoredPosition.x, (0f - x2) / 2f, x2 / 2f), 0f);
				activeLineCanvasGroup.alpha = 1f;
				Action<float> updateValue = delegate(float f)
				{
					RectTransform activeLineTransform5 = m_ActiveLineTransform;
					Vector2 anchoredPosition3 = m_ActiveLineTransform.anchoredPosition;
					activeLineTransform5.anchoredPosition = new Vector2(f, anchoredPosition3.y);
				};
				Vector2 anchoredPosition2 = m_ActiveLineTransform.anchoredPosition;
				m_ActiveLinePosTweener = TweenManager.TweenFloat(updateValue, anchoredPosition2.x, 0f, m_AnimationDuration);
				Action<float> updateValue2 = delegate(float f)
				{
					RectTransform activeLineTransform4 = m_ActiveLineTransform;
					Vector2 sizeDelta4 = m_ActiveLineTransform.sizeDelta;
					activeLineTransform4.sizeDelta = new Vector2(f, sizeDelta4.y);
				};
				Vector2 sizeDelta3 = m_ActiveLineTransform.sizeDelta;
				float x3 = sizeDelta3.x;
				Vector2 properSize3 = m_LineTransform.GetProperSize();
				m_ActiveLineSizeTweener = TweenManager.TweenFloat(updateValue2, x3, properSize3.x, m_AnimationDuration);
			}
		}

		private void AnimateActiveLineDeselect(bool instant = false)
		{
			CancelActivelineTweeners();
			if (!(activeLineTransform == null))
			{
				if (instant)
				{
					activeLineCanvasGroup.alpha = 0f;
					return;
				}
				activeLineCanvasGroup.alpha = 1f;
				m_ActiveLineAlphaTweener = TweenManager.TweenFloat(delegate(float f)
				{
					activeLineCanvasGroup.alpha = f;
				}, activeLineCanvasGroup.alpha, 0f, m_AnimationDuration);
			}
		}

		private void CancelHintTextTweeners()
		{
			TweenManager.EndTween(m_HintTextFloatingValueTweener);
			m_AnimateHintText = false;
		}

		private void CancelActivelineTweeners()
		{
			TweenManager.EndTween(m_ActiveLineSizeTweener);
			TweenManager.EndTween(m_ActiveLinePosTweener);
			TweenManager.EndTween(m_ActiveLineAlphaTweener);
		}

		private void SetHintLayoutToFloatingValue()
		{
			if (!(m_HintTextTransform == null))
			{
				if (m_FloatingHint)
				{
					m_HintTextTransform.offsetMin = new Vector2(m_LeftSectionWidth, m_BottomSectionHeight);
					m_HintTextTransform.offsetMax = new Vector2(0f - m_RightSectionWidth, 0f - Tween.Linear(m_TopSectionHeight, 0f, hintTextFloatingValue, 1f));
					hintTextObject.fontSize = Mathf.RoundToInt(Tween.Linear(inputText.fontSize, m_FloatingHintFontSize, hintTextFloatingValue, 1f));
					float num = Tween.Linear(inputText.fontSize, m_FloatingHintFontSize, hintTextFloatingValue, 1f);
					float num2 = num / (float)hintTextObject.fontSize;
					m_HintTextTransform.localScale = new Vector3(num2, num2, num2);
					hintTextCanvasGroup.alpha = 1f;
				}
				else
				{
					m_HintTextTransform.offsetMin = new Vector2(m_LeftSectionWidth, m_BottomSectionHeight);
					m_HintTextTransform.offsetMax = new Vector2(0f - m_RightSectionWidth, 0f);
					hintTextObject.fontSize = inputText.fontSize;
					m_HintTextTransform.localScale = Vector3.one;
					hintTextCanvasGroup.alpha = 1f - hintTextFloatingValue;
				}
			}
		}

		public void SetLayoutDirty()
		{
			LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
		}

		public void SetLayoutHorizontal()
		{
			if (!TweenManager.TweenIsActive(m_HintTextFloatingValueTweener))
			{
				hintTextFloatingValue = ((inputField.isFocused || inputField.text.Length > 0) ? 1 : 0);
				SetHintLayoutToFloatingValue();
			}
			RectTransform inputTextTransform = this.inputTextTransform;
			float leftSectionWidth = m_LeftSectionWidth;
			Vector2 offsetMin = this.inputTextTransform.offsetMin;
			inputTextTransform.offsetMin = new Vector2(leftSectionWidth, offsetMin.y);
			RectTransform inputTextTransform2 = this.inputTextTransform;
			float x = 0f - m_RightSectionWidth;
			Vector2 offsetMax = this.inputTextTransform.offsetMax;
			inputTextTransform2.offsetMax = new Vector2(x, offsetMax.y);
			if (m_LineTransform != null)
			{
				RectTransform lineTransform = m_LineTransform;
				float leftSectionWidth2 = m_LeftSectionWidth;
				Vector2 offsetMin2 = m_LineTransform.offsetMin;
				lineTransform.offsetMin = new Vector2(leftSectionWidth2, offsetMin2.y);
				RectTransform lineTransform2 = m_LineTransform;
				float x2 = 0f - m_RightSectionWidth;
				Vector2 offsetMax2 = m_LineTransform.offsetMax;
				lineTransform2.offsetMax = new Vector2(x2, offsetMax2.y);
			}
			if (m_ValidationTextTransform != null)
			{
				RectTransform validationTextTransform = m_ValidationTextTransform;
				float leftSectionWidth3 = m_LeftSectionWidth;
				Vector2 offsetMin3 = m_ValidationTextTransform.offsetMin;
				validationTextTransform.offsetMin = new Vector2(leftSectionWidth3, offsetMin3.y);
				RectTransform validationTextTransform2 = m_ValidationTextTransform;
				float x3 = 0f - m_RightSectionWidth;
				Vector2 offsetMax3 = m_ValidationTextTransform.offsetMax;
				validationTextTransform2.offsetMax = new Vector2(x3, offsetMax3.y);
			}
			if (m_CounterTextTransform != null)
			{
				RectTransform counterTextTransform = m_CounterTextTransform;
				float leftSectionWidth4 = m_LeftSectionWidth;
				Vector2 offsetMin4 = m_CounterTextTransform.offsetMin;
				counterTextTransform.offsetMin = new Vector2(leftSectionWidth4, offsetMin4.y);
				RectTransform counterTextTransform2 = m_CounterTextTransform;
				float x4 = 0f - m_RightSectionWidth;
				Vector2 offsetMax4 = m_CounterTextTransform.offsetMax;
				counterTextTransform2.offsetMax = new Vector2(x4, offsetMax4.y);
			}
			if (this.caretTransform != null)
			{
				RectTransform caretTransform = this.caretTransform;
				Vector2 offsetMin5 = this.inputTextTransform.offsetMin;
				float x5 = offsetMin5.x;
				Vector2 offsetMin6 = this.caretTransform.offsetMin;
				caretTransform.offsetMin = new Vector2(x5, offsetMin6.y);
				RectTransform caretTransform2 = this.caretTransform;
				Vector2 offsetMax5 = this.inputTextTransform.offsetMax;
				float x6 = offsetMax5.x;
				Vector2 offsetMax6 = this.caretTransform.offsetMax;
				caretTransform2.offsetMax = new Vector2(x6, offsetMax6.y);
			}
		}

		public void SetLayoutVertical()
		{
			RectTransform inputTextTransform = this.inputTextTransform;
			Vector2 offsetMax = this.inputTextTransform.offsetMax;
			inputTextTransform.offsetMax = new Vector2(offsetMax.x, 0f - m_TopSectionHeight);
			if (!TweenManager.TweenIsActive(m_HintTextFloatingValueTweener))
			{
				hintTextFloatingValue = ((inputField.isFocused || inputField.text.Length > 0) ? 1 : 0);
				SetHintLayoutToFloatingValue();
			}
			if ((bool)m_LeftContentTransform)
			{
				ILayoutController[] componentsInChildren = m_LeftContentTransform.GetComponentsInChildren<ILayoutController>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].SetLayoutVertical();
				}
				RectTransform leftContentTransform = m_LeftContentTransform;
				float x = m_LeftContentOffset.x;
				Vector2 offsetMax2 = this.inputTextTransform.offsetMax;
				leftContentTransform.anchoredPosition = new Vector2(x, offsetMax2.y - (float)(m_InputText.fontSize / 2) - 2f + m_LeftContentOffset.y);
			}
			if ((bool)m_RightContentTransform)
			{
				ILayoutController[] componentsInChildren2 = m_RightContentTransform.GetComponentsInChildren<ILayoutController>();
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					componentsInChildren2[j].SetLayoutVertical();
				}
				RectTransform rightContentTransform = m_RightContentTransform;
				float x2 = m_RightContentOffset.x;
				Vector2 offsetMax3 = this.inputTextTransform.offsetMax;
				rightContentTransform.anchoredPosition = new Vector2(x2, offsetMax3.y - (float)(m_InputText.fontSize / 2) - 2f + m_RightContentOffset.y);
			}
			if (m_LineTransform != null)
			{
				m_LineTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, m_BottomSectionHeight, 1f);
			}
			if (this.caretTransform != null)
			{
				RectTransform caretTransform = this.caretTransform;
				Vector2 offsetMin = this.caretTransform.offsetMin;
				float x3 = offsetMin.x;
				Vector2 offsetMin2 = this.inputTextTransform.offsetMin;
				caretTransform.offsetMin = new Vector2(x3, offsetMin2.y);
				RectTransform caretTransform2 = this.caretTransform;
				Vector2 offsetMax4 = this.caretTransform.offsetMax;
				float x4 = offsetMax4.x;
				Vector2 offsetMax5 = this.inputTextTransform.offsetMax;
				caretTransform2.offsetMax = new Vector2(x4, offsetMax5.y);
			}
		}

		public void CalculateLayoutInputHorizontal()
		{
			m_LayoutSize.x = ((!m_ManualPreferredWidth) ? (-1f) : m_ManualSize.x);
			m_LeftSectionWidth = 0f;
			m_RightSectionWidth = 0f;
			if (m_LeftContentTransform != null && m_LeftContentTransform.gameObject.activeSelf)
			{
				Vector2 properSize = m_LeftContentTransform.GetProperSize();
				m_LeftSectionWidth = properSize.x;
				m_LeftSectionWidth += 8f;
			}
			if (m_RightContentTransform != null && m_RightContentTransform.gameObject.activeSelf)
			{
				Vector2 properSize2 = m_RightContentTransform.GetProperSize();
				m_RightSectionWidth = properSize2.x;
				m_RightSectionWidth += 8f;
			}
		}

		public void CalculateLayoutInputVertical()
		{
			if (m_FloatingHint)
			{
				m_TopSectionHeight = GetSmallHintTextHeight();
				m_TopSectionHeight += 4f;
			}
			else
			{
				m_TopSectionHeight = 0f;
			}
			if (m_HasCharacterCounter || m_HasValidation)
			{
				m_BottomSectionHeight = 0f;
				if (m_HasCharacterCounter && counterText != null)
				{
					m_BottomSectionHeight = counterText.preferredHeight;
				}
				else if (m_HasValidation && validationText != null)
				{
					m_BottomSectionHeight = validationText.preferredHeight;
				}
				m_BottomSectionHeight += 4f;
			}
			else
			{
				m_BottomSectionHeight = 0f;
			}
			if (m_FitHeightToContent)
			{
				m_LayoutSize.y = GetTextHeight() + 4f;
				m_LayoutSize.y += m_TopSectionHeight;
				m_LayoutSize.y += m_BottomSectionHeight;
			}
			else
			{
				m_LayoutSize.y = ((!m_ManualPreferredHeight) ? (-1f) : m_ManualSize.y);
			}
			if ((bool)m_LeftContentTransform)
			{
				ILayoutElement[] componentsInChildren = m_LeftContentTransform.GetComponentsInChildren<ILayoutElement>();
				componentsInChildren = componentsInChildren.Reverse().ToArray();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].CalculateLayoutInputVertical();
				}
			}
			if ((bool)m_RightContentTransform)
			{
				ILayoutElement[] componentsInChildren2 = m_RightContentTransform.GetComponentsInChildren<ILayoutElement>();
				componentsInChildren2 = componentsInChildren2.Reverse().ToArray();
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					componentsInChildren2[j].CalculateLayoutInputVertical();
				}
			}
		}
	}
}
